﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class ShipDescriptionPanel : MonoBehaviour
{
    public Text m_Name2;
    public Text m_StructL;
    public Text m_ElectircL;
    public Text m_ElectircIncrementL;//
    public Text m_MassL;
    public Text m_PurityL;
    public Text m_DetectRangeL;//
    public Text m_ImpetusL;
    public Text m_AngleImpetusL;//
    public Text m_WeaponSlotsL;
    public Text m_DescriptionL;

    public GameObject m_NameO;
    public GameObject m_StructO;
    public GameObject m_ElectircO;
    public GameObject m_ElectircIncrementO;//
    public GameObject m_MassO;
    public GameObject m_PurityO;
    public GameObject m_DetectRangeO;//
    public GameObject m_ImpetusO;
    public GameObject m_AngleImpetusO;//
    public GameObject m_WeaponSlotsO;
    public GameObject m_DescriptionO;

    public Ship Ship
    {
        set {
            m_Ship = value; 
            if(m_Ship)
            {
                m_PurityO.SetActive(false);

                var stone = m_Ship as Stone;
                if (stone)
                {
                    m_PurityO.SetActive(true);
                    m_PurityL.text = stone.m_Purity.ToString("F2");
                }

                m_Name2.text = m_Ship.m_ShipStruct.m_Name;
                m_StructL.text = m_Ship.m_ShipStruct.m_StructurePointMax.ToString();
                m_ElectircL.text = m_Ship.m_ShipStruct.m_ElectricMax.ToString();
                m_ElectircIncrementL.text = m_Ship.m_ShipStruct.m_ElectricIncrement.ToString()+"/s";
                m_DetectRangeL.text = (m_Ship.m_ShipStruct.DetectRange*100).ToString();
                m_MassL.text = m_Ship.GetComponent<Rigidbody2D>().mass.ToString("F2");
                m_ImpetusL.text = m_Ship.m_ShipStruct.VelocityMax.ToString();
                m_AngleImpetusL.text = m_Ship.m_ShipStruct.RotateSpeedMax.ToString();


                int bigWeeaponCount = 0;
                int middleWeeaponCount = 0;
                int smallWeeaponCount = 0;
                for (int i=0; i<m_Ship.m_WeaponSlots.Count; ++i)
                {
                    switch(m_Ship.m_WeaponSlots[i].m_Level)
                    {
                        case Weapon.Level.LEVEL_BIG:
                            bigWeeaponCount++;
                            break;
                        case Weapon.Level.LEVEL_MIDDLE:
                            middleWeeaponCount++;
                            break;
                        case Weapon.Level.LEVEL_SMALL:
                            smallWeeaponCount++;
                            break;
                    }
                }
                m_WeaponSlotsL.text = "大型武器槽x"+bigWeeaponCount+", 中型武器槽x"+ middleWeeaponCount+", 小型武器槽x"+ smallWeeaponCount;
                m_DescriptionL.text = m_Ship.m_ShipStruct.Description;
            }
            else
            {
                m_Name2.text = "none";
                m_StructL.text = "none";
                m_ElectircL.text = "none";
                m_MassL.text = "none";
                m_ImpetusL.text = "none";
                m_WeaponSlotsL.text = "none";
                m_DescriptionL.text = "none";
            }
        }
        get { 
            return m_Ship; 
        }
    }
    Ship m_Ship;
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
    }
}
